package com.article.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.ServletRequestAware;

import com.article.entity.TreeNode;
import com.article.jsonfactory.ConvertJsonUtils;
import com.article.service.ITreeNodeService;

@SuppressWarnings("serial")
public class TreeNodeAction extends BaseAction implements ServletRequestAware {
	private HttpServletRequest request;
	private ITreeNodeService treeNodeService;
	private static final Logger logger = Logger.getLogger(TreeNodeAction.class);

	/**
	 * 显示父节点下的所有子节点
	 * 
	 * @return
	 */
	public String showNode() {
		logger.debug("显示子节点...");
		// 从查询字符串中取出父节点id
		String node = request.getParameter("node");
		// 根据父节点查询所有子节点
		List<TreeNode> list = treeNodeService.findByParentId(node);
		// 将结果集转换成json数据
		String json = ConvertJsonUtils.convertListToJson(list);
		// 将数据输出到客户端
		outJson(json);
		return null;
	}

	public void setServletRequest(HttpServletRequest arg0) {
		request = arg0;
	}

	public void setTreeNodeService(ITreeNodeService treeNodeService) {
		this.treeNodeService = treeNodeService;
	}

}
